Skip to content

feat(context): assert the identity a repo must use, not just report it - #505

Merged
sandstream merged 1 commit into
mainfrom
feat/503-identity-assertion
Aug 20, 2026
Merged

sandstream merged 1 commit into
mainfrom
feat/503-identity-assertion

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes #503 (requirements 1, 3 and 4; 2 is scoped out below).

The asymmetry this removes

kit check printed the identity and stopped:

✓ vercel   authenticated   <account>

kit context check asserted vercel.team / vercel.project — ids read from .vercel/project.json — and had no field for who is logged in. Meanwhile [context.gcloud].account is an identity, declared and asserted like git.email. So the mechanism existed for exactly one tool, which is what made this a gap rather than a design.

New: vercel.user, github.user (distinct from github.org, which is the remote's owner), convex.account.

state verdict
declared, differs mismatch — red, non-zero exit
declared, unreadable (not logged in, tool absent) unknown — "cannot tell" is not "wrong account"
not declared not checked

What the gap cost

A session whose CLI was logged in as a personal account with read-only rights on the production environment read a filtered variable list as a complete one:

  • env ls showed four variables and looked whole — those were the ones that also existed in preview, which is what made the list credible;
  • every production-only variable was invisible;
  • env pull --environment=production failed with "Production Project Environment Variable not found", which reads as "does not exist", not "you may not see it";
  • env add … production was refused for permissions — the only message that named permissions, and it came last.

Two contradictory conclusions in a row, settled by a web UI. kit check was green throughout, and the identity line was the one place that could have said something.

Remediation names the mechanism, not "log in again"

A global login is what produces a wrong identity, so telling someone to log in again is telling them to repeat the cause. On mismatch:

✗ vercel.user  expected deploy-bot, live someones-personal-account
  vercel: use a per-profile config dir (`vercel -Q .vercel-profile <cmd>`, or VERCEL_TOKEN /
  `--token` for one command). A global `vercel login` is what makes one identity leak across repos.
  Anything you already read as this identity may have been a PARTIAL view — permissions filter
  listings silently.

gh auth switch, gcloud config configurations activate, AWS_PROFILE, stripe project profiles — and for convex, the honest answer that it has no profiles: ~/.convex/config.json is global and convex login overwrites it, so the only isolation is CONVEX_DEPLOY_KEY / CONVEX_DEPLOYMENT per repo.

That last line is requirement 4 made concrete: when a command's output depends on the caller's role, the wrong identity does not merely mean "wrong account" — it means everything read under it may have been a subset.

The suggestion block hedges, deliberately

kit context check on an undeclared repo now offers the identities it detected:

[context.github]
org = "acme"          # from origin remote — authoritative
user = "octocat"      # ⚠ the gh account logged in NOW — VERIFY it is right for THIS repo

The live identity is exactly what the lock exists to question, so it is offered with the same hedge the ambient gcloud values already carry. A reading that is not a real identity — a convex config with a token but no email — is reported in the check but never offered as a value to declare: asserting a parenthetical note would compare a sentence.

Tests

src/context-identity.test.ts — 15, against the pure comparator and the pure helpers:

  • declared-and-differs → mismatch with both values; declared-and-equal → ok; unreadable → unknown; undeclared → absent from the findings entirely
  • normaliseIdentity takes the answer rather than the CLI's chatter (vercel whoami prints a "Retrieving…" line first), and returns null for errors, not-authenticated notices, and implausibly long output
  • readConvexAccount reads the global config, reports logged-in-but-unreadable without ever echoing the token, and returns null when there is no config
  • identityRemediation names a per-tool mechanism for each supported tool, says outright that convex has none, and has nothing to say about a tool without one
  • suggestContextToml offers hedged identities and refuses to offer a parenthetical note as a declaration

Scoped out

Requirement 2 — reporting the resolved ROLE (authenticated <account> (Developer)). It needs authenticated per-tool API calls, which needs the caching / offline / "unavailable with a reason" story that #500 just built for registry lookups. It should reuse that machinery rather than grow a second one, so it is a follow-up rather than a rushed second implementation.

Verification

  • npm test: 4407 tests, 0 fail, 0 skipped (macOS, non-root)
  • kit self-audit: 16 rules, 0 fail, 0 warn · eslint src: 0 errors · prettier --check clean · coverage gate: no net-new untested files
  • kit context check exercised against this repo's real gh / vercel / convex state

🤖 Generated with Claude Code

kit printed `✓ vercel authenticated <account>` and compared it to nothing, while
`kit context check` asserted only ids read from repo-local files. So a CLI
answering as the wrong account was green — and the mechanism to fix that already
existed for exactly one tool (`gcloud.account`), which is what made the omission
a gap rather than a design (#503).

New declarable identities, behaving exactly like git.email: `vercel.user`,
`github.user` (distinct from github.org, the remote's owner) and
`convex.account`. Declared → asserted; mismatch → red and non-zero; unreadable
→ `unknown`, because "cannot tell" and "wrong account" are different findings;
undeclared → not checked at all.

What the gap cost, measured: a session whose CLI was logged in as a personal
account with read-only rights on the production environment read a FILTERED
variable list as a complete one. `env ls` showed four variables and looked whole
— the ones that also existed in preview — while every production-only variable
was invisible, and `env pull --environment=production` failed as though the
variable did not exist. Two contradictory conclusions were drawn before a web UI
settled it.

A mismatch now names the mechanism that scopes an identity to a repo, because a
global login is what produces a wrong one: vercel -Q / VERCEL_TOKEN, gh auth
switch, gcloud config configurations activate, AWS_PROFILE, stripe project
profiles — and for convex, that it has NO profiles (~/.convex/config.json is
global and `convex login` overwrites it), so the isolation is CONVEX_DEPLOY_KEY /
CONVEX_DEPLOYMENT per repo. It also says the part that turns a wrong identity
into wrong conclusions out loud: anything already read as this identity may have
been a PARTIAL view, because permissions filter listings silently.

The ready-to-paste block offers detected identities hedged ("⚠ the gh account
logged in NOW — VERIFY it is right for THIS repo"), since the live identity is
precisely what the lock exists to question, and a value that is not a real
identity is reported but never offered as something to declare.

Requirement 2 of the issue — reporting the resolved ROLE where an API exposes it
— is deliberately not in this change: it needs authenticated per-tool API calls
and the caching/offline story that #500 just built for registry lookups, and it
should reuse that rather than grow a second one.

Closes #503

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit b998b3e into main Aug 20, 2026
19 checks passed
@sandstream
sandstream deleted the feat/503-identity-assertion branch August 20, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kit reports which account a CLI is logged in as, but never asserts it — so a wrong-identity tool reads green and its filtered output reads complete

1 participant